import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({
  data: {
    swiperList: [],
    TabInfos: []
  },
  // 页面开始加载 就会触发
  onLoad: function (options) {
    // Standard sync of swiper_list
    const swiper_list = wx.getStorageSync("swiper_list");
    if (!swiper_list) {
      this.getSwiperList();
    } else {
      if (Date.now() - swiper_list.time > 1000 * 10) {
        this.getSwiperList();
      } else {
        this.setData({
          swiperList: swiper_list.data
        })
      }
    }
    // Standard sync of swiper_list
    const tab_infos_recent = wx.getStorageSync("tab_infos_recent");
    if (!tab_infos_recent) {
      this.getRecent();
    } else {
      if (Date.now() - tab_infos_recent.time > 1000 * 10) {
        this.getRecent();
      } else {
        this.setData({
          TabInfos: tab_infos_recent.data
        })
      }
    }
  },

  async getSwiperList(){
    const data = {}
    // const res = request({
    //   url: "/swiper",
    //   data: data
    // })
    const swiper_list = [
      {
        "goods_id": 0,
        "image_src": "/static/1.jpg"
      },
      {
        "goods_id": 1,
        "image_src": "/static/2.jpeg"
      },
      {
        "goods_id":2,
        "image_src": "/static/3.jpeg"
      }
    ]
    this.setData({
      swiperList: swiper_list
    })
  },

  async getRecent() {
    const data = {}
    // const res = request({
    //   url: "/tabinfosrecent",
    //   data: data
    // })
    const tab_infos_recent = [
      {
        id: 0,
        goods_name: "Test Case",
        goods_price: 23.33,
        tags: [
          {
              id: 0,
              tag_name: "tag0",
              image_src: "/static/1.jpg"
          },
          {
              id: 2,
              tag_name: "tag2",
              image_src: "/static/2.jpeg"
          },
          {
              id: 85,
              tag_name: "tag85",
              image_src: "/static/3.jpeg"
          },
          {
              id: 166,
              tag_name: "tag166",
              image_src: "/static/c1.png"
          }
        ],
        image_src:"/static/g1.jpg",
        marked:false
      },
      {
        id: 2333,
        goods_name: "Test Case 2",
        goods_price: 2000,
        tags: [
          {
              id: 0,
              tag_name: "tag0",
              image_src: "/static/1.jpg"
          },
          {
              id: 2,
              tag_name: "tag2",
              image_src: "/static/2.jpeg"
          },
          {
              id: 85,
              tag_name: "tag85",
              image_src: "/static/3.jpeg"
          }
        ],
        image_src: "/static/g2.jpg",
        marked:true
      },
      {
        id: 3333,
        goods_name: "Test Case 3",
        goods_price: 0.55,
        tags: [
          {
              id: 1,
              tag_name: "tag1",
              image_src: "/static/1.jpg"
          }
        ],
        image_src: "/static/g3.jpg",
        marked:false
      }
    ]
    this.setData({
      TabInfos: tab_infos_recent
    })
  }
  
})
